package com.fpc.java8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;



public class Streamdemo  {
	
	  public static List<User> createList() {
		  
	        User user = new User(1L, "by", 18, "音乐");
	        User user1 = new User(2L, "gz", 26, "音乐");
	        User user2 = new User(3L, "aby", 19, "旅行");
	        List<User> userList = new ArrayList();
	        userList.add(user);
	        userList.add(user1);
	        userList.add(user2);
	        return userList;

	    }

	    public static void main(String[] args) {
	        List<User> userList = createList();
	        // List对象转List<Long>
	        List<Long> longList = userList.stream().map(o->o.getId()).collect(Collectors.toList());
	        
	        List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
	          // 获取对应的平方数
	        List<Integer> squaresList = numbers.stream().map( i -> i*i).collect(Collectors.toList());
	        
	        List<Integer> squaresListtwo = userList.stream().map( i -> i.getAge()*2).collect(Collectors.toList());
	        
	        squaresList.forEach(System.out::println); 
	        userList.forEach(obj->{
	        	int ddfsfad=obj.getAge()+2;
	        }); 
	        //List<User> squaresListTwo = userList.stream().map( i -> i.getAge() *2).distinct().collect(Collectors.toList());
	        
	     }
	    
	  

}
